Forms in HTML are used to collect user input. Example: login form, registration form, feedback form, etc.
<form>
... form elements here ...
</form>
The <form> tag defines the form. Each input uses a name attribute which is important when sending data to the server.
<form>
Username: <input type="text" name="username">
</form>
Radio buttons let users select only one option from a group. All radio buttons in the same group must have the same name.
Gender:
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female
The for attribute in <label> tag connects a label to an input field using its id. Clicking the label selects the input automatically.
<label for="email">Email:</label>
<input type="email" id="email" name="email">
Checkboxes let users select multiple options.
Hobbies:
<input type="checkbox" name="hobby" value="reading"> Reading
<input type="checkbox" name="hobby" value="sports"> Sports
<input type="checkbox" name="hobby" value="music"> Music
The placeholder shows hint text inside the input box until the user types something.
<input type="text" name="fullname" placeholder="Enter your full name">
The file input type allows users to upload files from their computer.
<input type="file" name="resume">
Special input types exist for email and phone numbers.
<input type="email" name="email" placeholder="Enter your email">
<input type="tel" name="phone" placeholder="Enter your phone number">
The <textarea> is used for multi-line input (like comments or feedback).
<textarea name="message" rows="5" cols="40">
Type your message here...
</textarea>
Dropdown menus let users select from a list of options.
<label for="city">Choose a city:</label>
<select name="city" id="city">
<option value="delhi">Delhi</option>
<option value="mumbai">Mumbai</option>
<option value="kolkata">Kolkata</option>
</select>
The submit button is used to send form data.
<input type="submit" value="Submit">
Adding the required attribute ensures the field must be filled before submitting.
<input type="text" name="username" placeholder="Enter username" required>